/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dameki.game;

import dameki.core.GlobalVars;
import java.util.ArrayList;

/**
 *
 * @author Tobi
 */
public class State {
    
    private Stone[][] field;
    private ArrayList<Stone> whitestones;
    private ArrayList<Stone> blackstones;
    
    public State() {
        field = new Stone[8][8];
        whitestones = new ArrayList<>();
        blackstones = new ArrayList<>();
    }
    
    public void init() {
        for (int x = 0; x < 12; x++) {
            whitestones.add(new Stone(true));
            blackstones.add(new Stone(false));
        }
        
        int w = 0;
        int b = 0;
//        field[1][1] = whitestones.get(0);
//        field[1][1].setPosX(1);
//        field[1][1].setPosY(1);
//        field[0][0] = whitestones.get(1);
//        field[0][0].setPosX(0);
//        field[0][0].setPosY(0);
//        field[2][2] = blackstones.get(0);
//        blackstones.get(0).setPosX(2);
//        blackstones.get(0).setPosY(2);
//        field[4][4] = blackstones.get(1);
//        blackstones.get(1).setPosX(4);
//        blackstones.get(1).setPosY(4);
        for (int x = 1; x < 8; x += 2) {
            field[0][x] = whitestones.get(w++);
            field[0][x].setPosX(x);
            field[0][x].setPosY(0);
            field[2][x] = whitestones.get(w++);
            field[2][x].setPosX(x);
            field[2][x].setPosY(2);
            field[6][x] = blackstones.get(b++);
            field[6][x].setPosX(x);
            field[6][x].setPosY(6);
        }
        for (int x = 0; x < 8; x += 2) {
            field[7][x] = blackstones.get(b++);
            field[7][x].setPosX(x);
            field[7][x].setPosY(7);
            field[5][x] = blackstones.get(b++);
            field[5][x].setPosX(x);
            field[5][x].setPosY(5);
            field[1][x] = whitestones.get(w++);
            field[1][x].setPosX(x);
            field[1][x].setPosY(1);
        }
    }
    
    public Stone[][] getField() {
        return this.field;
    }
    
    public void removeStone(Stone s) {
        field[s.getPosY()][s.getPosX()] = null;
        if (s.getColor()) {
            whitestones.remove(s);
        } else {
            blackstones.remove(s);
        }
    }
    
    public ArrayList<Stone> getStoneList(boolean color){
        if(color==GlobalVars.COLOR_W)
            return whitestones;
        else return blackstones;
    }
}
